<?php
/**
 * author      : Yxhsea.
 * email       : Yxhsea@foxmail.com
 * createTime  : 2017/1/15 20:33
 * description :
 */
namespace Admin\Controller;
use Think\Controller;

/**
 * Class BaseController
 * @package Admin\Controller
 */

class BaseController extends Controller
{
    public function _initialize()
    {

//        if (!session('admin_id')) {
//             echo "<script>";
//             echo "var haha = confirm('非法访问！正在跳转登录页面！');";
//             echo "if(haha==true){
//                 window.location='".__APP__."/Login/index';
//                 }else{window.location='".__APP__."/Login/index'}";
//             echo "</script>";
//        }
//
//
//        $id = $_SESSION['admin_id'];
//        $type=I("get.type");
//        $role_id = M('admin')->where(['id' => session('admin_id')])->getField('role_id');
//        $auth = M('Role')->where(['id' => $role_id])->getField('auth');
//
//        $list = unserialize($auth);// 获取当前的权限
//        $list = implode(',', $list);
//        if (!$list) {
//            return true;
//        }
//
//        $getlist = M('auth')->where('id in (' . $list . ')')->select();
//
//        foreach ($getlist as $k => $v) {
//
//            $path = $v['path'];
////            var_dump($path);die;
//            $pattem = '/\w+/';
//            $result = [];
//
//            preg_match_all($pattem, $path, $result);// 正则表达式提取模块名称
//            $get_sum_list[] = $result[0][0];
//
//        }
//
//        $controller = CONTROLLER_NAME;
//
////        var_dump('111');die;
////        var_dump($controller);die;
////        var_dump($get_sum_list);die;
//        if (!in_array($controller, $get_sum_list)) {
////               var_dump('222');die;
//            if (strtoupper($controller) == 'INDEX' || strtoupper($controller) == 'LOGIN') {
//                return true;
//            }
//            echo "<script>";
//            echo "var haha = confirm('您没有访问权限！');";
//            echo "if(haha==true){
//                 window.location='".__APP__."/Index/index';
//                 }else{window.location='".__APP__."/Index/index'}";
//            echo "</script>";
//        }
    }

    /**
     * 更改状态
     * @param $id @id
     * @param $tableName @表名
     * @param $status @状态值
     */
    public function setStatus($id, $tableName, $status)
    {
        if (IS_AJAX) {
            $data = array(
                'status' => $status
            );
            $res = M($tableName);
            $res->where(['id' => $id]);
            $res->save($data);
            if ($res) {
                $this->ajaxReturn(['info' => '操作成功', 'status' => '1', 'sql' => $sql]);
            } else {
                $this->ajaxReturn(['info' => '操作失败', 'status' => '0', 'sql' => $sql]);
            }
        } else {
            $this->ajaxReturn(['info' => '非法操作']);
        }

    }

    /**
     * 删除
     * @param $id
     * @param $tableName
     */
    public function delete($id, $tableName)
    {

    }


    /*
     *
     * @actime_name:操作名称
     * @time:操作时间
     * */
    public function rizhi($action_name, $time)
    {


    }
}